package com.oa.common.result;

import lombok.Getter;
import lombok.Setter;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 系统rest公共返回类
 *
 * @author cuichao
 */
@Getter
@Setter
public class Result {

    private int status;

    private Object data;

    private String extension;

    public Result() {
    }

    public Result(int status, Object data) {
        this.status = status;
        this.data = data;
    }

    public Result(int status, String extension) {
        this.status = status;
        this.extension = extension;
    }


    public static Result success(Object data) {
        return new Result(200, data);
    }

    public static Result failure(SystemCode code, String extension){
        return new Result(code.getCode(), extension);
    }

    public static Result failure(String extension){
        return new Result(SystemCode.exception.getCode(), extension);
    }

    public static Result  paginationResult(long page , long limit, long total ,List<? extends Object> result){
        Map<String,Object> data = new HashMap<>();
        data.put("page",page);
        data.put("limit",limit);
        data.put("total",total);
        data.put("result",result);
        return success(data);
    }


}
